<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace utiles;

use model\UserSession;

/**
 * Description of SessionWrapper
 *
 * @author Jorge
 */
class SessionUtil {

    //put your code here
    public static function getUserSession() {
        if (isset($_SESSION['userSession'])) {
            return $_SESSION['userSession'];
        }

        return null;
    }

    public static function isAdmin() {
        if (strcasecmp($_SESSION['userSession']->getPerfil(), 'admin') == 0) {
            return true;
        }
        return false;
    }

    public static function isUser() {
        if (strcasecmp($_SESSION['userSession']->getPerfil(), 'user') == 0) {
            return true;
        }
        return false;
    }

    public static function isUserCobranza() {
        if (strcasecmp($_SESSION['userSession']->getPerfil(), 'user_cob') == 0) {
            return true;
        }
        return false;
    }

    public static function getDatosEmpresa() {

        if (isset($_SESSION['datos_empresa'])) {
            return $_SESSION['datos_empresa'];
        }

        return null;
    }

    public static function getUrlBase() {
        if (isset($_SESSION['BASE'])) {
            return $_SESSION['BASE'];
        }

        return null;
    }

    public static function isLogged() {
        if (empty($_SESSION['usuario']) || !isset($_SESSION['usuario'], $_SESSION['perfil'])) {
            session_destroy();
            header("Location: index.php");
        }
        if (!isset($_SESSION['perfil'])) {
            die("Usuario no autorizado");
        }
    }
    
    public static function start(){
        session_start();
    }

}
